/*
 * UsartHandler.cpp
 *
 * Created: 3/6/2013 11:13:05 PM
 *  Author: brodzki
 */ 

#define F_CPU 8000000UL // clock speed - 8Mhz (unsigned long)

#include <avr/interrupt.h>
#include "UsartHandler.h"

void UsartHandler::initialize()
{
	#define BAUD 57600
	#include <util/setbaud.h>

	// set high and low bit using values calculated in util/setbaud.h
	UBRRH = UBRRH_VALUE;
	UBRRL = UBRRL_VALUE;
	#if USE_2X
		UCSRA |= (1 << U2X);
	#else
		UCSRA &= ~(1 << U2X);
	#endif

	// data: 8 bits
	// stop: 1 bit
	// parity: none
	UCSRC = (1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0);

	// enable TX, RX and their interrupts
	UCSRB = (1<<TXEN) | (1<<TXCIE) | (1<<RXEN) | (1<<RXCIE);
}